﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Acms.DatabaseTest.Helpers
{
    public static class SiteHelpers
    {
        private static string SelectClause
        {
            get { return "select * from acms.sites"; }
        }

        public static void Site_Add(this TestConnection source, int id, string name, string root, bool useTopics, bool useMenus, bool deleted)
        {
            string sql = string.Format("set identity_insert acms.sites on \n insert into acms.sites ([Id], [Name],[Root],[UseTopics],[UseMenus],[Deleted]) values ({0}, '{1}', '{2}', {3}, {4}, {5}) \n set identity_insert acms.sites off", id, name, root, useTopics ? "1" : "0", useMenus ? "1" : "0", deleted ? "1" : "0");
            source.Execute(sql);
        }

        public static Dictionary<string, object> Site_GetByID(this TestConnection source, int id)
        {
            string sql = string.Format("{0} where id = {1}", SelectClause, id);
            return source.ExecuteWithResults(sql).FirstOrDefault();
        }

        public static List<Dictionary<string, object>> Site_GetAll(this TestConnection source)
        {
            return source.ExecuteWithResults(SelectClause);
        }
    }
}
